package leetCode.q165;

import java.util.ArrayList;
import java.util.List;

public class Me {
    /**
     * 比较版本号
     */
    public int compareVersion(String version1, String version2) {
        List<Integer> l1 = new ArrayList<>();
        List<Integer> l2 = new ArrayList<>();

        for (String s : version1.split("\\.")) {
            l1.add(Integer.parseInt(s));
        }
        for (String s : version2.split("\\.")) {
            l2.add(Integer.parseInt(s));
        }

        boolean flag = l1.size() > l2.size();
        boolean flag1 = l2.size() > l1.size();
        while (flag||flag1){
            if (flag){
                l2.add(0);
            }else {
                l1.add(0);
            }
            flag = l1.size() > l2.size();
            flag1 = l2.size() > l1.size();
        }

        for(int i=0;i<l1.size();i++){
            if(l1.get(i)> l2.get(i)) return 1;
            if(l1.get(i)< l2.get(i)) return -1;
        }

        return 0;
    }

    public static void main(String[] args) {
        System.out.println(new Me().compareVersion("0012.2.03", "2.3"));
    }
}
